#!/bin/bash

source $DRAW_INI
source $DRAW_CFG

if [ $TARGET_FLANKS_FILE == "WGS" ];then
  LTAG=""
else
  LTAG="-L $TARGET_FLANKS_FILE"
fi

java -Xmx1g \
   -jar $GATK \
   -T RealignerTargetCreator \
   -R $REF_FASTA \
   -nt $GATK_THREADS \
   $LTAG \
   --known $DBSNP_REF \
   --read_filter UnmappedRead \
   -I ${1}.bam \
   -o ${1}.indel_calls.interval_list

EXITSTATUS=$?

#force error when missing output
if [ ! -s "${1}.indel_calls.interval_list" ]
then
 echo "Missing indel_calls ${1}.indel_calls.interval_list, can not continue"
 exit 100
fi

exit $EXITSTATUS

